package simple; /**
 * @projectName study-note
 * @package PACKAGE_NAME
 * @className PACKAGE_NAME.SumArr
 */

import java.util.Arrays;

/**
 * SumArr
 * @description 数组和
 * @author answer_wx
 * @date 2022/7/4 18:50
 * @version 1.0
 */
public class SumArr {
    public static int sumArr(int[] arr, int index) {
        if (index == arr.length - 1) {
            return arr[index];
        }
        return arr[index] + sumArr(arr, index + 1);
    }

    public static int maxArr(int[] arr, int index) {
        if (index == arr.length - 2) {
            return arr[index] <= arr[index + 1] ? arr[index + 1] : arr[index];
        }
        int max = maxArr(arr, index + 1);
        return arr[index] >= max ? arr[index] : max;
    }

    public static void main(String[] args) {
        int[] arr = {1, 7, 5, 3, 4};
        System.out.println(sumArr(arr, 0));
        System.out.println(maxArr(arr, 0));
    }
}